package com.cpi.basilos.warehouse.converter;

import org.apache.log4j.Logger;

import com.cpi.basilos.warehouse.dto.WarehouseDTO;
import com.cpi.basilos.warehouse.exception.WarehouseException;
import com.cpi.basilos.warehouse.view.WarehouseView;
import com.cs.common.exception.CSException;
import com.cs.common.utils.NumberUtil;

public class WarehouseConverter {
	private static org.apache.log4j.Logger logger = Logger.getLogger(WarehouseConverter.class);
	public WarehouseView convertDTOToView(WarehouseDTO warehouseDTO)throws WarehouseException{
		WarehouseView warehouseView = null;
		try{
			warehouseView = new WarehouseView();
			warehouseView.setBatch(warehouseDTO.isBatch());
			warehouseView.setCode(warehouseDTO.getCode());
			warehouseView.setCompany(warehouseDTO.getCompany());
			warehouseView.setId(warehouseDTO.getId());
			warehouseView.setLocation(warehouseDTO.isLocation());
			warehouseView.setName(warehouseDTO.getName());
			warehouseView.setNumber(warehouseDTO.getNumber());
			warehouseView.setTotalStock(NumberUtil.convertQuantity(warehouseDTO.getTotalStock()));
		}catch(Exception exception){
			WarehouseException warehouseException = null;
			logger.error(exception);
			exception.printStackTrace(System.err);
			warehouseException = new WarehouseException(exception,CSException.LAYER_CONVERTER, CSException.ACTION_SELECT);
			throw warehouseException;
		}
		return warehouseView;
	}
}